<?php

namespace app\admin\controller;

use app\admin\server\Menu;
use app\admin\server\Upload;
use think\Session;

class Admin extends AdminBase
{
    /**
     *主体
     * @return mixed
     */
    public function index()
    {
        $user = Session::get('user', 'admin');
        if (empty($user)) $this->redirect('Login/index');

        //菜单
        $powerid = ($user['adid'] == 1) ? [] : explode(',', $user['powerid']);
        $menu = Menu::getMenu(0, 1, $powerid);
        $this->assign('menu', $menu);

        //用户信息
        $this->assign('user', $user);

        return $this->fetch();
    }

    /**
     * 上传图片
     * @return \think\response\Json
     */
    public function uploads()
    {
        try {
            $path = Upload::uploads('file');

            $json = ['code' => 200, 'msg' => 'success', 'path' => $path];
        } catch (\Exception $e) {
            $json = ['code' => 400, 'msg' => $e->getMessage()];
        }
        return json($json);
    }
}